Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update tricrypto-ng #23

Merged
merged 56 commits into from
Sep 19, 2023
Merged

Conversation

bout3fiddy
Copy link
Collaborator

Following compiler/infra related vulnerabilities and exploits, There is now an even more need to footgun-proof the tricrypto-ng contracts.

The existing implementations do not suffer from the vulnerabilities in the following Vyper releases:

image

https://twitter.com/vyperlang/status/1685692973051498497?s=20

However, native token transfers on EVM increase the chances of introducing unwanted footguns. For instance, the pools vulnerable to malfunctioning reentrancy checks were only exploitable if pool methods had native eth transfers to exploiter.

This pull request attempts to remove the most obvious footguns pre-emptively. Following merge, there will be a proposal to replace the existing tricrypto-ng blueprint contract with the new version.

…hen pool is not ramping; add comments on how claiming admin fees involves gulping and should be used carefully when optimistic transfers are involved
@bout3fiddy bout3fiddy marked this pull request as ready for review August 14, 2023 16:07
"""
received_amounts: uint256 = 0
coin_balance: uint256 = ERC20(coins[_coin_idx]).balanceOf(self)
recorded_balance: uint256 = self.balances[_coin_idx]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

recorded_balance should go inside if because else is not using it, and we are reading it twice needlessly

@@ -536,7 +464,7 @@ def add_liquidity(

# --------------------- Get prices, balances -----------------------------

precisions: uint256[N_COINS] = self._unpack(self.packed_precisions)
precisions: uint256[N_COINS] = self._unpack(packed_precisions)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why unpack packed precisions every time?? Isn't it better to store them in an immutable array? Then you wouldn't spend gas on unpacking

# Only enabled in exchange_received: it expects the caller
# of exchange_received to have sent tokens to the pool before
# calling this method.
received_amounts = coin_balance - recorded_balance
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So here we need received_amounts = coin_balance - self.balances[coin_idx]

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

well we need the recorded balances before updating balances. so this won't do.

fee_params: uint256[3] = self._unpack(self.packed_fee_params)
f: uint256 = MATH.reduction_coefficient(xp, fee_params[2])

# During parameter ramping, we raise fees and disable admin fee claiming
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Honestly - I don't like raising fees here. I understand it is for safety, but price oracles would be somewhat imprecise when this is the case

)

last_xcp: uint256 = self.get_xcp(self.D, self.price_scale_packed)
return (last_xcp * (10**18 - alpha) + cached_xcp_oracle * alpha) / 10**18
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, no, this is wrong!! You do like we are doing with price oracles now:

output = self.last_xcp * (1 - alpha) + previous_oracle * alpha
self.last_xcp = self.get_xcp(...)

Otherwise your value can jump - same problem we have with an external oracle now. Yes you'd need to save two variables

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

@bout3fiddy bout3fiddy merged commit ffe7304 into curvefi:main Sep 19, 2023
2 of 3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants